home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14293 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: dispatch.news.demon.net!demon!thesett.demon.co.uk
  2. From: Andy@thesett.demon.co.uk (Andy Goodwin)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: New printf - like function, is it possible?
  5. Date: Fri, 29 Mar 1996 20:31:48 GMT
  6. Message-ID: <311240d2.593861@news.demon.co.uk>
  7. References: <4eqb3a$2r5@pan.otol.fi>
  8. NNTP-Posting-Host: thesett.demon.co.uk
  9. X-NNTP-Posting-Host: thesett.demon.co.uk
  10. X-Newsreader: Forte Agent .99c/16.141
  11.  
  12. On 1 Feb 1996 12:18:50 GMT, tkes@rhea.otol.fi (Timo Sakari) wrote:
  13.  
  14. >
  15. >Hi!
  16. >
  17. >Do you C-gurus have any solutions to this problem?
  18. >
  19. >I am programming under MS Windows 3.1 (this is NOT an OS spesific 
  20. >question!)and I would like to create
  21. >some kind of modified print function, which syntax should be something
  22. >like normal printf; because in Windows printf can't be used, everything
  23. >printed to screen has to come through message boxes etc, and before 
  24. >displaying anything, the string to displayed has to be formed. I have 
  25. >created my own printing function, which wants parameters string and winID
  26. >to know where to put that string, something like this: 
  27. >
  28. >sprintf(printStr, "some sfuff, variables %d, %f, etc", var1, var2);
  29. >PrintToWin(DEBUG_WIN_1, printStr);
  30. >
  31. >However, I want to write a "better" printing function, where string to be
  32. >formed doesn't need to be formatted first, it can be displayed and formed
  33. >at the same time in the same syntax like printf, something like these:
  34. >
  35. >PrintToWin(DEBUG_WIN_1, "some stuff etc, %d, %f, %s, var1, var2, str1);
  36. >PrintToWin(OTHER_WIN, "anything that printf accepts");
  37. >
  38. >So I want to print almost anything with this function without having
  39. >to write many functions to different argument types/number of arguments.
  40. >This should be possible in C++ (is it?), but is it possible in C ?
  41. >Can this be achieved by using void pointers and macros etc., or should
  42. >I give up and don't waste my time on this?
  43. >
  44. >Any help would be greatly appreciated. Thanks.
  45. >
  46. >
  47. >
  48. >--
  49. >   Timo Sakari          phone: (981) 5306 070 
  50. >   Haapanatie 2 D 408   email: tkes@rhea.otol.fi
  51. >   90150 OULU           WWW: http://www.otol.fi/~tkes/
  52. >   FINLAND
  53.  
  54. Look in your C help for the following functions
  55.  
  56. type va_arg( va_list arg_ptr, type );
  57.  
  58. void va_end( va_list arg_ptr );
  59.  
  60. void va_start( va_list arg_ptr );    (UNIX version)
  61.     void va_start( va_list arg_ptr, prev_param );    (ANSI)
  62.  
  63. Microsoft C gives an example of averaging 'n' integers
  64.  
  65. Your function would have to be prototyped as 
  66.  
  67. void PrintToWin( int, const char *, ... ) ;
  68. You would have to process the format string your self or use the
  69. vsprintf function after generating a va_list variable.
  70.  
  71.